package com.csx.data.routing.sample.service.impl;

import com.csx.data.routing.sample.entity.MonthBillEntity;
import com.csx.data.routing.sample.mapper.MonthBillsMapper;
import com.csx.data.routing.sample.service.IMonthBillsService;
import com.csx.data.routing.sample.utils.TableTimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

// Service实现类
@Service
public class MonthBillsServiceImpl implements IMonthBillsService {
    @Autowired
    private MonthBillsMapper billsMapper;

    @Override
    public int insert(MonthBillEntity monthBills) {
        // 获取要插入数据的表名
        TableTimeUtils.getDataByTable(monthBills);
        // 返回插入数据的状态
        return billsMapper.insertSelective(monthBills);
    }

    // 在MonthBillsServiceImpl实现类中撰写具体的实现
    @Override
    public MonthBillEntity selectBySerialNumber(MonthBillEntity monthBills) {
        // 根据流水号获取要查询数据的具体表名
        TableTimeUtils.getTableBySerialNumber(monthBills);
        // 调用Dao层根据流水号查询数据的方法
        return billsMapper.selectBySerialNumber(monthBills);
    }

    // 在MonthBillsServiceImpl实现类中撰写具体的实现
    @Override
    public List<MonthBillEntity> rangeQueryByDate(String startTime, String endTime) {
        // 获取范围查询时的SQL语句
        String sql = TableTimeUtils.getRangeQuerySQL(startTime,endTime);
        return billsMapper.rangeQueryByDate(sql);
    }


}